let kz = true
const myGuoDu = () => {
   let box = document.querySelector(".top-box")
   if (kz) {
      box.classList.remove("active2")
      box.classList.add("active1")
      document.querySelector("img").style.src = "./img/02.jpg";

      kz = !kz
   } else {
      box.classList.remove("active1")
      box.classList.add("active2")

      document.querySelector("img").style.src = "./img/01.jpg";

      kz = !kz
   }


}


document.querySelector(".login-btn>button").addEventListener("click", function () {
   let name = document.querySelectorAll(".login-input>input")[0].value
   let password = document.querySelectorAll(".login-input>input")[1].value
   console.log(name, password);
  
   //   登录
   axios({
      url: 'http://big-event-vue-api-t.itheima.net/api/login',
      method: 'POST',
      data: {
         "username": name,
         "password": password,
         "repassword": password
      }
   }).then(res => {
      console.log(res.data);
      if (res.data.code == 0) {
         alert("登录成功!")
         window.location.href = "./图书管理.html"
      } else {
         if (res.data.message.search(/username/i) > 0) {
            return alert("用户名输入错误!")
         }
         if (res.data.message.search(/password/i) > 0) {
            return alert("密码输入错误!")

         }
      }

   })
})


document.querySelector(".register-btn>button").addEventListener("click",function(){
  let username=document.querySelectorAll(".register-input>input")[0].value
  let password=document.querySelectorAll(".register-input>input")[1].value
  let repassword=document.querySelectorAll(".register-input>input")[2].value

  //注册
axios({
   url: 'http://big-event-vue-api-t.itheima.net/api/reg',
   method: 'POST',
   data: {
      "username": username,
      "password": password,
      "repassword": repassword
   }
}).then(res => {
console.log(res);
if(res.data.code==0){
   alert("注册成功!")
   location.reload()
}else{
  
if(res.data.message.search(/用户名被占用/i) ==0){
   return alert("用户名被占用!")
}
if (res.data.message.search(/username/i) > 0) {
   return alert("用户名格式(1-10位大小写字母和数字)")
}
if (res.data.message.search(/repassword/i) > 0) {
   return alert("两次密码输入不一致!")

}
if (res.data.message.search(/password/i) > 0) {
   return alert("6-15位非空格字符!")

}

}

})
})


